package cn.iocoder.yudao.module.infra.controller.admin.config;

import cn.iocoder.yudao.framework.common.pojo.CommonResult;
import jakarta.annotation.PostConstruct;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import java.util.HashMap;
import java.util.Map;

import static cn.iocoder.yudao.framework.common.pojo.CommonResult.success;

// doc：https://nacos.io/zh-cn/docs/nacos-spring.html
// https://github.com/nacos-group/nacos-spring-boot-project/wiki/%E7%94%A8%E6%88%B7%E4%BD%BF%E7%94%A8%E6%96%87%E6%A1%A3
@RestController
@RequestMapping("/infra/config_test")
@Slf4j
public class ConfigTestController {
    @Value(value = "${test_name:Value}")
    private String testNameValue; // 无法热更

    //@NacosValue(value = "${test_name:NacosValue}", autoRefreshed = true)
    private String testNameNacosValue; // 可以热更

    @PostConstruct
    public void init() {
        log.info("测试配置, testNameValue = {}", testNameValue);
        log.info("测试配置, testNameNacosValue = {}", testNameNacosValue);
    }

    @GetMapping(value = "/get")
    @ResponseBody
    public CommonResult<Map<String, Object>> get() {
        final Map<String, Object> data = new HashMap<>();
        data.put("testNameValue", testNameValue);
        data.put("testNameNacosValue", testNameNacosValue);
        return success(data);
    }

}
